package com.googlecode.lemyriapode.implementation;

import com.googlecode.lemyriapode.regle.Regle;
import com.googlecode.lemyriapode.type.*;
import com.googlecode.lemyriapode.regle.Position;
import com.googlecode.lemyriapode.type.AFRegle.IClosure;
import com.googlecode.lemyriapode.type.AFRegle.IPredicate;

/**
 * Implementation pour explorer UNE dir
 * @author Gilles
 */
public class FDirection extends AFPosition {

    public FDirection(final Regle regle) {
        super();
        this.regle = regle;


    }

    @Override
    public boolean continuer(int n, Position position) {
        this.pos = position;
        return isLastDirection.eval();

    }

    @Override
    public void executer(int n, Position position) {
        _Case_C();
        _Piece_En_C();
        getDir();
        if (isDirectionAutoriser.eval()) {
            SiSinon(isMultiDeplacement, exploreDir, exploreDir1Case);
//        regle.getRegleA(this).execute();
        }
        getNext_dir();
    }

    @Override
    public Object stopper(int n, Position e) {
        return null;
    }

    public void SiSinon(IPredicate pred, IClosure trueclos, IClosure falseclos) {
        if (pred.eval()) {

            trueclos.exec();
        } else {
            falseclos.exec();

        }
    }

    public void getNext_dir() {
        echq.dir = dir.next();
    }

    public void getDir() {
        dir = pos.echiquier.dir;
    }

    public void _Case_C() {
        getEchiquier();
        _c = echq._c;
    }

    public void getEchiquier() {
        echq = pos.echiquier;
    }

    public void _Piece_En_C() {
        piece_c = regle.position.posCourante.get(_c);
//            piece_c = f.pos.getPiece(_c);
    }
}
